<template>
	<view style="display: flex;flex-direction: column;">
		<u-search
			style="margin: 10rpx;"
			v-model="keyword"
			search-icon-color="#FF6347"
			placeholder="请输入店铺名"
			shape="round"
			@custom="searchClick"
			@search="searchClick"
			@clear="clear"
			:show-action="true"
		></u-search>
		<!-- //人员列表 -->
		<view class="main-list">
			<view class="main-check" v-for="(item, index) in peopleList" :key="index">
				<view class="main-check-image" @click="confirm(index)" style="display: flex; width: 100%; height: auto">
					<view class="" style="display: flex; width: 100%;height: 100%;justify-content: space-between;">
						<!-- <view class="text-lg text-bold text-blue">身份: {{item.data.position}}</view> -->
						<view class="text-lg text-bold">店铺名:
							<text class="text-red text-xl">{{ item.data.name }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- //弹窗 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
const db = uniCloud.database();
export default {
	data() {
		return {
			keyword: '',
			searchCheck: false,
			peopleList: [] //预选人员
		};
	},
	onLoad() {},
	methods: {
		//将输入框内容清除
		clear() {
			this.keyword = '';
		},
		//开始搜索
		searchClick(value) {
			let that = this;
			if (value == "") {
				this.$refs.uToast.show({
					title: '搜索不能为空',
					type: 'error'
				});
				return;
			}
			console.log('关键字', value);
			let keyword = value;
			uni.showLoading({
				title: '正在搜索中...'
			})
			//请求后端该订单搜索出来''
			db.collection('storeList')
				.where({
					'data.name': new RegExp(keyword, 'i')
				})
				.get({})
				.then((res) => {
					if(res.result.data.length > 0){
						uni.hideLoading();
						that.peopleList = res.result.data;
						console.log('人员数据：',that.peopleList)
					}else{
						uni.hideLoading();
						that.$refs.uToast.show({
							title: '暂时没有数据',
							type: 'error'
						});
						console.log('暂时没有数据')
						that.peopleList = [];
					}
				})
				.catch((err)=>{
					uni.hideLoading();
					that.$refs.uToast.show({
						title: '网络错误',
						type: 'error'
					});
				})
		},
		//选中人员
		confirm(index){
			let that = this;
			getApp().globalData.peopleMoneyInfo = that.peopleList[index];
			getApp().globalData.peopleMoneyInfoshauxin = true;
			setTimeout(function() {
				uni.navigateBack();
			}, 500);
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	background-color: #f5f5f5;
}
.search_box {
	margin: 10rpx;
}
.main-list {
	display: flex;
	width: 100%;
	height: 100%;
	flex-direction: column;
	align-items: center;
}
.main-check {
	display: flex;
	flex-direction: column;
	width: 90%;
	height: 100rpx;
	margin-top: 20rpx;
	padding: 0 20rpx;
	align-items: center;
	justify-content: center;
	border-radius: 20rpx;
	background: #fff;
}
.main-check-image {
	align-items: center;
}
</style>
